package com.sun.decrypt;

import com.sun.decrypt.utils.HexUtils;
import com.sun.decrypt.utils.MessageDigestUtils;
import org.apache.commons.codec.DecoderException;
import org.apache.commons.codec.binary.Hex;
import org.apache.commons.codec.digest.DigestUtils;
import org.junit.Test;

import java.io.UnsupportedEncodingException;
import java.util.Arrays;

public class MD5Test {


    @Test
    public void jdkMD5(){
        String str = "哈啊哈";
        String algorithm = "MD5";
        String hex = MessageDigestUtils.doDigest(str, algorithm);
        System.out.println(hex);
        //当字符串太大时使用
//        digest.update(str.getBytes(UTF8));
//        digest.digest();

    }
    //codec来实现md5
    @Test
    public void test2() throws UnsupportedEncodingException {
        byte[] bytes = new byte[1];
        bytes[0] = 15;
        String hexString = Hex.encodeHexString(bytes);
        System.out.println(hexString);

        String str = "哈啊哈";
        String hex = DigestUtils.md5Hex(str.getBytes("utf-8"));
        System.out.println(hex);
    }
    @Test
    public void test3() throws DecoderException {
        byte[] bytes = new byte[1];
        bytes[0] = 15;
        String hexStr = HexUtils.convertBytes2HexStr(bytes);
        System.out.println(hexStr);
        System.out.println(Hex.encodeHex(bytes));
        byte[] bytes1 = HexUtils.converHexStrBytes(hexStr);
        System.out.println(Arrays.toString(bytes1));
        System.out.println(Arrays.toString(Hex.decodeHex(hexStr)));

    }

}
